package com.mxx.common.data.jpa;

import com.mxx.common.core.SFunction;
import com.mxx.common.utils.SFunctionUtil;

import javax.persistence.criteria.*;

public class LambdaUpdateSpecHelper<T> extends AbstractUpdateSpecHelper<LambdaUpdateSpecHelper<T>, SFunction<T, ?>> {

    public LambdaUpdateSpecHelper(Root root, CriteriaBuilder criteriaBuilder, CriteriaQuery criteriaQuery, CriteriaUpdate criteriaUpdate) {
        super(root, criteriaBuilder, criteriaQuery, criteriaUpdate);
    }

    @Override
    public LambdaUpdateSpecHelper<T> getTarget() {
        return this;
    }


    @Override
    protected Path get(SFunction<T, ?> key) {
        String fieldName = SFunctionUtil.getFieldName(key);
        try {
            return root.get(fieldName);
        } catch (IllegalArgumentException ex) {
            throw new RuntimeException(ex.getMessage());
        }
    }
}
